﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using TjZheng.Core.Mvc;
using TjZheng.Framework;

namespace TjZheng.JiaLi.Process
{
    public class TicketContext : JiaLiContext
    {
        public TicketInfo ValidTicketInfo { get; private set; }
        public XmlDocument ActiveXml { get; private set; }
        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime ExpireTime { get; private set; }
        public TicketContext()
        {
            this.ActiveXml = TicketInfo.TicketPath.CreateXmlDocument();
            if (this.ActiveXml == null)
            {
                throw new Exception("对不起，激活文件丢失");
            }

            this.ValidTicketInfo = TicketInfo.GetTicketInfo("Valid");

            if (this.ValidTicketInfo != null && this.ValidTicketInfo.ExpireTime.HasValue)
            {
                this.ExpireTime = DateTime.Now.Add(this.ValidTicketInfo.ExpireTime.Value.AddHours(8).Subtract(InternetTimeHelper.GetInternetTime()));
            }
        }
    }
}
